from os import access

from selenium.webdriver.common.by import By

from common.Uilt import forum_driver

class write:
    driver = ""
    def __init__(self):
        self.driver = forum_driver.driver
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("asd")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

    def write_null_faid(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit > svg").click()

        text1 = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div").get_attribute("style")
        assert text1 != "text-align: left; display: none;"#说明发布失败
        forum_driver.getwinshot()

    def write_Suc(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        # self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre").clear()

        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("自动化测试04")
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(20) > a > i").click()
        # self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre").send_keys("自动化测试01")
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()

        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(2) > a > span.nav-link-title").click()

        text2 = self.driver.find_element(By.CSS_SELECTOR,"#article_list_count_board").text

        assert text2 == "帖子数量: 5" #说明发布成功
        forum_driver.getwinshot()


write = write()
write.write_null_faid()
write.write_Suc()
write.driver.quit()

